<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class OperationLogMiddleware
{
    public function handle(Request $request, Closure $next)
    {
        $adminId = $request->admin_id ?? 0;

        $ip = $request->getClientIp();
        $uri = $request->decodedPath();
        $method = strtolower($request->method());

        //由于上传的文件也在$request->all()中，用$_REQUEST替换
        //        $params = $request->all();
        $params = $_REQUEST;

        app('model_admin_log')->insert([
            'admin_id'  => $adminId,
            'client_ip' => $ip,
            'uri'       => $uri,
            'method'    => $method,
            'content'   => serialize($params),
        ]);

        return $next($request);
    }
}
